# 使用系统的api来创建vgg
# 代码来源于以下的链接
# https://blog.csdn.net/Wei_sx/article/details/145055459
import keras.src.applications.vgg16
import numpy as np
from keras.api.preprocessing import image
# from keras.src.applications import vgg16
from keras.src.applications.vgg16 import VGG16
from keras.src.applications.vgg16 import preprocess_input

model = VGG16(weights="imagenet", include_top=True)

image_path = './dataset/img.png'
img = image.load_img(image_path, target_size=(224, 224))

img_array = image.img_to_array(img)

img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)

predictions = model.predict(img_array)
top_predictions = keras.src.applications.vgg16.decode_predictions(predictions, top=5)[0]
for i, (imagenet_id, label, score) in enumerate(top_predictions):
    # print(f'{i + 1}: {label} ({score:.2f)}')
    print(f'{i + 1}: {label} ({score:.2f})')
    # print(f"{i + 1}: {label} ({score:.2f})")
